/*
package com.castudio.COS;

import com.google.gson.Gson;
import com.qiniu.http.Response;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.Region;
import com.qiniu.storage.UploadManager;
import com.qiniu.storage.model.DefaultPutRet;
import com.qiniu.util.Auth;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import org.apache.commons.lang3.RandomStringUtils;

import javax.servlet.ServletContext;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;


@Component
@ConfigurationProperties(prefix = "cos")
public class COSConfig{

    private static String baseUrl;
    private static String accessKey;
    private static String secretKey;
    private static String bucketName;

    @Value("${cos.baseUrl}")
    public void setBaseUrl(String baseUrl) {
        this.baseUrl = baseUrl;
    }
    @Value("${cos.accessKey}")
    public void setAccessKey(String accessKey) {
        this.accessKey = accessKey;
    }
    @Value("${cos.secretKey}")
    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }
    @Value("${cos.bucketName}")
    public void setBucketName(String bucketName) {
        this.bucketName = bucketName;
    }

    */
/*上传文件*//*

    public static String uploadFile(MultipartFile fileMul, String cosPath, ServletContext context) throws Exception {

        //临时文件路径
        String temporaryFile = context.getRealPath("/") + "/upload" + "temporaryFile";
        //校验临时文件是否存在
        File localFile = new File(temporaryFile);
        if (!localFile.exists()) {
            //临时文件不存在，则创造临时文件
            localFile.mkdirs();
        }
        //创造临时文件名称
        String fileName = fileMul.getOriginalFilename();
        String name = "/" + RandomStringUtils.randomNumeric(6) + System.currentTimeMillis() + System.nanoTime() + RandomStringUtils.randomNumeric(6) + fileName.substring(fileName.lastIndexOf('.'));
        //创建临时文件图片
        temporaryFile = temporaryFile + name;
        FileOutputStream fos;
        fos = new FileOutputStream(temporaryFile);
        fos.write(fileMul.getBytes());
        fos.flush();
        fos.close();
        //使用COS
        File file = new File(temporaryFile);
        // 1 初始化用户身份信息(accessKey,secretKey)
        COSCredentials cred = new BasicCOSCredentials(accessKey,secretKey);
        */
/* 2 设置bucket的地域
        * clientConfig中包含设置region，https(默认http)，超时，代理等set方法 *//*

        Region region = new Region("ap-guangzhou");
        ClientConfig clientConfig = new ClientConfig(region);
        //使用https协议
        clientConfig.setHttpProtocol(HttpProtocol.https);
        // 3 生成COS客户端
        COSClient client = new COSClient(cred,clientConfig);
        // 格式化时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        PutObjectRequest request = new PutObjectRequest(bucketName, cosPath + sdf.format(new Date()) + name, file);
        client.putObject(request);

        String saveUrl = baseUrl + request.getKey();
        // 删除用户上传临时文件
        File localImgFile = new File(temporaryFile);
        localImgFile.delete();

        return saveUrl;

    }

}
*/
